package offer.offer61;

import java.util.Arrays;

/**
 * @Author: wjy
 * @Date: 2021/11/3 11:06
 */
public class Solution {

    public static void main(String[] args) {

        //int[] ints = {4, 6, 7, 5, 4};
        //int[] ints = {5, 4, 3, 2, 1};
        //int[] ints = {0, 0, 1, 2, 5};
        //int[] ints = {0, 0, 2, 2, 5};
        int[] ints = {8,7,11,0,9};

        Solution solution = new Solution();
        System.out.println(solution.isStraight(ints));

    }

    public boolean isStraight(int[] nums) {
        if (nums.length == 0) {
            return false;
        }

        int temp = 0;
        int count = 0;

        Arrays.sort(nums);

        for (int i = 0; i < nums.length-1; i++) {

            if (nums[i] == 0) {
                count++;
                continue;
            }
            if (nums[i + 1] == nums[i]) {
                return false;
            }
            temp += (Math.abs(nums[i + 1] - nums[i]) - 1);
        }

        if ((count - temp) >= 0) {
            return true;
        } else {
            return false;
        }
    }

}
